Class SamplingSensorBase<UNIT>
Base class for sensors and other updating classes that want to support having their updates consumed by observers that can optionally use filters
Assembly: Meadow.Foundation.dll
View Source
public abstract class SamplingSensorBase<UNIT> : ObservableBase<UNIT>, IObservable<IChangeResult<UNIT>>, ISamplingSensor<UNIT>, ISensor<UNIT>, ISensor, ISamplingSensor where UNIT : struct
Inheritance: System.Object
-> Meadow.Foundation.ObservableBase<UNIT>
Derived:
Implements:
System.IObservable<Meadow.IChangeResult<<UNIT>>>
, Meadow.Peripherals.Sensors.ISamplingSensor<<UNIT>>
, Meadow.Peripherals.Sensors.ISensor<<UNIT>>
, Meadow.Peripherals.Sensors.ISensor
, Meadow.Peripherals.Sensors.ISamplingSensor
Properties
SamplingTokenSource
Sampling cancellation token source
View Source
protected CancellationTokenSource? SamplingTokenSource { get; set; }
Conditions
The last read conditions
View Source
public UNIT Conditions { get; protected set; }
IsSampling
Gets a value indicating whether the sensor is currently in a sampling loop. Call StartSampling() to spin up the sampling process.
View Source
public bool IsSampling { get; protected set; }
UpdateInterval
A TimeSpan
that specifies how long to
wait between readings. This value influences how often *Updated
events are raised and IObservable
consumers are notified.
View Source
public virtual TimeSpan UpdateInterval { get; protected set; }
Fields
samplingLock
Lock for sampling
View Source
protected object samplingLock
Methods
RaiseUpdated(UNIT)
Raised when the sensor has new data
View Source
protected void RaiseUpdated(UNIT newValue)
Parameters
Type | Name | Description |
---|---|---|
<UNIT> | newValue | The new sensor value as a generic |
ReadSensor()
Read value from sensor
View Source
protected abstract Task<UNIT> ReadSensor()
Returns
System.Threading.Tasks.Task<<UNIT>>
: unitized value### RaiseEventsAndNotify(IChangeResult<UNIT>)
Notify observers
View Source
protected virtual void RaiseEventsAndNotify(IChangeResult<UNIT> changeResult)
Parameters
Type | Name | Description |
---|---|---|
Meadow.IChangeResult<<UNIT>> | changeResult | provides new and old values |
Read()
Convenience method to get the current sensor readings. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.
View Source
public virtual Task<UNIT> Read()
Returns
System.Threading.Tasks.Task<<UNIT>>
StartUpdating(TimeSpan?)
Starts updating the sensor on the updateInterval frequency specified
View Source
public abstract void StartUpdating(TimeSpan? updateInterval = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.TimeSpan> | updateInterval | A TimeSpan that specifies how long to |
wait between readings |
StopUpdating()
Stops sampling the sensor
View Source
public abstract void StopUpdating()
Events
Updated
Event handler for updated values
View Source
public event EventHandler<IChangeResult<UNIT>> Updated
Event Type
System.EventHandler<Meadow.IChangeResult<<UNIT>>>
Implements
System.IObservable<Meadow.IChangeResult<<UNIT>>>
Meadow.Peripherals.Sensors.ISamplingSensor<<UNIT>>
Meadow.Peripherals.Sensors.ISensor<<UNIT>>
Meadow.Peripherals.Sensors.ISensor
Meadow.Peripherals.Sensors.ISamplingSensor